package tsvetanv.inventory.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import tsvetanv.inventory.dao.ArticleDao;
import tsvetanv.inventory.model.Article;
import tsvetanv.inventory.model.Product;

/**
 * The <code>ArticleServiceImpl</code> class implements the business logic
 * related with {@link Article} class.
 * 
 * @author Tsvetan Vasilev
 * 
 */

@Service("articleService")
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_UNCOMMITTED, timeout = 10)
public class ArticleServiceImpl implements ArticleService {

	@Autowired
	private ArticleDao dao;

	// --- Getters, Setters-----------------------------------------------------
	public void setDao(ArticleDao dao) {
		this.dao = dao;
	}

	// --- Methods -------------------------------------------------------------
	public void save(Article article) {
		dao.save(article);

	}

	public void update(Article article) {
		dao.update(article);

	}

	public void delete(Article article) {
		dao.delete(article);

	}

	@Transactional(readOnly = true)
	public Article findByArticleId(int articleId) {
		return dao.findByArticleId(articleId);
	}

	@Transactional(readOnly = true)
	public Article findByProductName(String productName) {
		return dao.findByProductName(productName);
	}

	@Transactional(readOnly = true)
	public List<Article> getAllArticles() {
		return dao.getAllArticles();
	}

}
